<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        /* 方法一  */

        /* html,body{
            height: 100%;
            position: relative;
        }
        .q1{
            width: 300px;
            height: 300px;
            position: absolute;
            background-color: red;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            margin: auto;
        } */





        /* 方法二 */
        /* html,body{
            position: relative;
            height: 100%;
        }
        .q1{
            width: 300px;
            height: 300px;
            position: absolute;
            background-color: yellow;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
        } */



        /* 方法三 */
        html,body{
            height: 100%;
            position: relative;
        }
        .q1{
            width: 300px;
            height: 300px;
            position: absolute;
            left: 50%;
            top: 50%;
            background-color: blue;
            margin-top: -150px;
            margin-left: -150px;
        }
    </style>
</head>
<body>
    <div class="q1">
        
    </div>
</body>
</html>